package com.snbc.Io;

import java.io.*;
import java.nio.charset.Charset;

/**
 * @Classname Stream_test_1
 * @Description TODO
 * @Date 2019/9/27 19:59
 * @Created by Acer
 */
public class Stream_test_1 {
    /**
     * 找出 E5 B1 8C 这3个十六进制对应UTF-8编码的汉字
     */
    public static void main(String[] args) throws IOException {
        byte[] data = new byte[]{(byte) 0xE5, (byte) 0xB1, (byte) 0x8C};
        File file = new File("F:\\123444mmm\\test.txt");
        if (!file.exists()) {//如果文件不存在
            file.getParentFile().mkdirs();//创建目录
            try {
                file.createNewFile();//创建文件
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            fos.write(data);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        InputStreamReader isr = new InputStreamReader(new FileInputStream(file), Charset.forName("utf-8"));
        char[] all = new char[(int)file.length()];
        isr.read(all);
        System.out.printf("这个汉字为:%s%n存于%s中",new String(all),file.getAbsoluteFile());
    }
}
